package com.eianiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.eianiao.bean.Category;
import com.eianiao.bean.DishFlavor;
import com.eianiao.dao.DishFlavorDao;
import com.eianiao.dto.DishDto;
import com.eianiao.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author eianiao
 * @Date 2022 06
 * @Version 1.0
 **/
@Service
@Transactional
public class DishFlavorServiceImpl implements DishFlavorService {

    @Autowired
    private DishFlavorDao dishFlavorDao;

    /**
     * 添加口味
     *
     * @param dishFlavor
     * @return
     */
    @Override
    public int add(DishFlavor dishFlavor) {
        return dishFlavorDao.insert(dishFlavor);
    }

    /**
     * 根据菜品id查询
     *
     * @param id
     * @return
     */
    @Override
    public List<DishFlavor> findByDishId(Long id) {
        LambdaQueryWrapper<DishFlavor> qw = new LambdaQueryWrapper<>();
        qw.eq(DishFlavor::getDishId,id);

        return dishFlavorDao.selectList(qw);
    }

    /**
     * 删除口味
     *
     * @param dishId
     * @return
     */
    @Override
    public int deleteByDishId(long dishId) {
        LambdaQueryWrapper<DishFlavor> qw = new LambdaQueryWrapper<>();
        qw.eq(DishFlavor::getDishId,dishId);
        return dishFlavorDao.delete(qw);
    }


}
